//
//  WKBViewController.m
//  WKBLinkTapLabel
//
//  Created by 614034542@qq.com on 04/13/2018.
//  Copyright (c) 2018 614034542@qq.com. All rights reserved.
//

#import "WKBViewController.h"
#import "UILabel+LinkTap.h"

@interface WKBViewController ()

@end

@implementation WKBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, [UIScreen mainScreen].bounds.size.width, 400)];
    [self.view addSubview:label];
    NSMutableAttributedString * attributedText = [[NSMutableAttributedString alloc] initWithString:@"测试一下链接,测试一下链接,测试一下链接,测试一下链接,测试一下链接,测试一下链接,测试一下链接,测试一下链接!"];
    
    [attributedText addAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor],
                                    NSUnderlineColorAttributeName:[UIColor blueColor],
                                    NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)
                                    } range:NSMakeRange(20, 5)];
    [attributedText addAttributes:@{NSForegroundColorAttributeName:[UIColor blueColor],
                                    NSUnderlineColorAttributeName:[UIColor blueColor],
                                    NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle)
                                    } range:NSMakeRange(10, 2)];
    label.numberOfLines = 0;
    label.attributedText = attributedText;
    [label tapWithURLTextRanges:@[@{@"loc":@"20",@"len":@"5"}, @{@"loc":@"10",@"len":@"2"}] tapAction:^(NSInteger location, NSAttributedString *tapText) {
        NSLog(@"点击的是\"%@\",它第%zd个字符",tapText.string,location);
    }];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
